<template>
  <div>
    <div class="tab">
      <div @click="handleBack">返回</div>
      <div>搜索</div>
    </div>

    <div class="content">
      <div class="header">
        <van-search
          style="width: 8rem; height: 80px; border-radius: 50px"
          v-model="value"
          placeholder="请输入搜索关键词"
          @keydown.enter="handleSearch"
        />
        <button>搜索</button>
      </div>
      <div class="container">
        <div class="item" v-for="item of list" :key="item.id">
          <div><img :src="item.imgUrl" /></div>
          <div>
            <div class="movieName">{{ item.movieTitle }}{{ item.name }}</div>
            <div class="movieMes">
              {{ item.size }}首,by {{ item.name }}. 播放{{ item.duration }}次
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
      list: [],
    };
  },
  methods: {
    handleSearch() {
      var list = [];
      this.$http(
        `http://47.108.197.28:3000/search?keywords=${this.value}`
      ).then((res) => {
        res.data.result.songs.forEach((item) => {
          var { id, duration, name } = item;
          var movieTitle = item.album.name;
          var size = item.album.size;
          this.$http(`http://47.108.197.28:3000/song/detail?ids=${id}`).then(
            (res) => {
              list.push({
                id,
                duration,
                name,
                movieTitle,
                size,
                imgUrl: res.data.songs[0].al.picUrl,
              });
            }
          );
        });
      });
      this.list = list;
    },
    handleBack() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
.van-cell{
  font-size: 30px !important;
  background-color: initial !important;
}
.tab {
  display: flex;
  align-items: center;
  height: 80px;
  font-size: 32px;
  padding: 0 2px;
  border-bottom: 1px solid #aaa;
}
.tab > div:nth-child(2) {
  margin-left: 260px;
  font-size: 38px;
}

.header {
  height: 100px;
  background-color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.header button {
  width: 100px;
  height: 60px;
  border: none;
  border-radius: 50px;
}
.container {
  padding: 20px 24px;
  box-sizing: border-box;
}
.item {
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.item > div:nth-child(1) {
  overflow: hidden;
}
.item > div img {
  width: 130px;
  height: 130px;
  border-radius: 20px;
}
.item > div:nth-child(2) {
  height: 130px;
  width: 540px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  flex-wrap: wrap;
}
.movieName {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.movieMes {
  font-size: 24px;
  color: rgba(0, 0, 0, 0.6);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
</style>